package com.kmproject.haifu.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.kmproject.haifu.mvp.contract.HomeNewsDetailContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.api.service.UserService;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.CommentListBean;
import com.kmproject.haifu.mvp.model.entity.beans.HomeNewsBean;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 08/24/2019 13:46
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class HomeNewsDetailModel extends BaseModel implements HomeNewsDetailContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;
    private UserService userService;

    @Inject
    public HomeNewsDetailModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
        userService = mRepositoryManager.obtainRetrofitService(UserService.class);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<ResultBean<HomeNewsBean>> getHomeNewsDetail(String headlineId) {
        return userService.getHomeNewsDetail("/app/headlineNews/viewHeadlineNews/" + headlineId);
    }

    @Override
    public Observable<ResultBean> addComment(Map<String, Object> maps) {
        return userService.addComment(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean> cancelComment(String commentId) {
        return userService.cancelComment(Api.USER_COMMENT_CANCEL_LIKE_COMMENT + commentId);
    }

    @Override
    public Observable<ResultBean> likeComment(String commentId) {
        return userService.likeComment(Api.USER_COMMENT_LIKE_COMMENT + commentId);
    }

    @Override
    public Observable<ResultBean<List<CommentListBean>>> getCommentList(Map<String, Object> maps) {
        return userService.getCommentList(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean> deleteComment(String commentId) {
        return userService.deleteComment(Api.USER_COMMENT_REMOVE_COMMENT + commentId);
    }
}